babl-cache: implement a better cache path on Win32
authorEdward E <develinthedetail@gmail.com>
Fri, 2 Dec 2016 00:39:11 +0000 (18:39 -0600)
committerØyvind Kolås <pippin@gimp.org>
Sat, 3 Dec 2016 19:58:16 +0000 (20:58 +0100)
Use SHGetFolderPathA() to get the user local data path
(the same path GEGL uses for plugins on Win32)

https://bugzilla.gnome.org/show_bug.cgi?id=774491

babl/babl-cache.c

index c8a5dbd5f75ff72097eea57a5aeda5ba591ccd6b..723ee50d9b1d807626f51b50824173adf12c311b 100644 (file)
  * <http://www.gnu.org/licenses/>.
  */
 
+#ifdef _WIN32
+#include <shlobj.h>
+#endif
+
 #include <time.h>
 #include <sys/stat.h>
 #include "config.h"
@@ -77,8 +81,13 @@ static const char *fish_cache_path (void)
   if (getenv ("HOME"))
     sprintf (path, "%s/.cache/babl/babl-fishes", getenv("HOME"));
 #else
-  if (getenv ("TEMP"))
+{
+  char win32path[4096];
+  if (SHGetFolderPathA (NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, win32path) == S_OK)
+    sprintf (path, "%s\\%s\\babl-fishes.txt", win32path, BABL_LIBRARY);
+  else if (getenv ("TEMP"))
     sprintf (path, "%s\\babl-fishes.txt", getenv("TEMP"));
+}
 #endif
 
   if (stat (path, &stat_buf)==0 && S_ISREG(stat_buf.st_mode))